package com.jinglvhuanjing.app.helper.statusbar;

import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;

import com.jinglvhuanjing.app.utils.ScreenUtils;



public class StatusBarGroupView extends LinearLayout {

    private boolean isEnableImmerseStatusBar = true;

    public void setEnableImmerseStatusBar(boolean enableImmerse) {
        this.isEnableImmerseStatusBar = enableImmerse;
        this.paddingTop();
    }

    public StatusBarGroupView(Context context) {
        super(context);
        this.paddingTop();
    }

    public StatusBarGroupView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.paddingTop();
    }

    public StatusBarGroupView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.paddingTop();
    }

    private void paddingTop() {
        int mStatusBarHeight = ScreenUtils.getStatusBarHeight(getContext());
        if (ScreenUtils.isSupportImmerseStatusBar() && isEnableImmerseStatusBar) {
            this.setPadding(getPaddingLeft(), mStatusBarHeight, getPaddingRight(), getPaddingBottom());
        } else {
            this.setPadding(getPaddingLeft(), 0, getPaddingRight(), getPaddingBottom());
        }
    }

    /**
     * 附加方法：获取当前状态栏的高度
     */
    public int getStatusBarHeight() {
        return ScreenUtils.getStatusBarHeight(getContext());
    }

    /**
     * 此方法是设置导航栏边距，也仅在5.0以上生效
     */
    public void setPaddingBottom(int paddingBottom) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            this.setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(), paddingBottom);
        }
    }
}